package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}21:03
 */
public class LeetCode718 {
    public int findLength(int[] A, int[] B) {
        if (A.length == 0 || B.length == 0){
            return 0;
        }
        int[][] dp = new int[A.length + 1][B.length + 1];
        int max = 0;
        for (int i = 1; i <A.length + 1; i++){
            for (int j = 1; j < B.length + 1; j++){
                if (A[i - 1] == B[j - 1]){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    max = Math.max(dp[i][j],max);
                }
            }
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new LeetCode718().findLength(new int[]{3, 2, 1, 4, 7}, new int[]{1, 2, 3, 2, 1}));
    }
}
